/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/authorizationTypeService.ts" />
/// <reference path="../src/tms.ts" />

describe("getAuthorizationTypeList",()=>{
    var injector:ng.auto.IInjectorService;
    var service:IAuthorizationTypeService;

    beforeEach(()=>{
        injector=angular.injector(['ng','tms']);
        service=injector.get<IAuthorizationTypeService>('authorizationTypeService');
    });

    //常规无条件获取
    it('get authorizationType list normal',(done)=>{
       service.getList(null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|0|10');
           done();
       },(err)=>{
           done.fail(err);
       });
    });

    //获取查询的分类名称包含 财务 的权限分类列表
    it('get authorizationType list by name \'财务\'',(done) => {
        service.getList('财务',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('财务|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取权限分类详情
    it('get detail',(done)=>{
        service.getDetail('2').then((res)=>{
            expect(res.data.name).toBe("财务");
            expect(res.data.level).toBe("一级");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加权限分类
    it('add authorizationType',(done)=>{
        service.add('测试','TMS平台').then((res)=>{
            expect(res.data.extData).toBe("测试|TMS平台");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑权限分类
    it('edit authorizationType',(done)=>{
        service.edit('2','财务','TMS平台').then((res)=>{
            expect(res.data.extData).toBe("2|财务|TMS平台");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除权限分类
    it('delete authorizationType',(done)=>{
        service.delete('3').then((res)=>{
            expect(res.data.extData).toBe("3");
            done();
        },(err)=>{
            done.fail(err);
        });
    });


});